﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Helper
{
  public  class GoogleMapAPI
    {
      public static void GetLatLonByAdd(string add, ref string lat, ref string lon)
      {
          try
          {
              string geocoderUri = string.Format(@"http://maps.googleapis.com/maps/api/geocode/xml?address=" + add + "&sensor=true");
              XmlDocument geocoderXmlDoc = new XmlDocument();
              geocoderXmlDoc.Load(geocoderUri);
              //XmlNamespaceManager nsMgr = new XmlNamespaceManager(geocoderXmlDoc.NameTable);
              //nsMgr.AddNamespace("geo", @"http://www.w3.org/2003/01/geo/wgs84_pos#");
              XmlNodeList xnList = geocoderXmlDoc.SelectNodes("/GeocodeResponse/result/geometry/location");
              foreach (XmlNode xn in xnList)
              {
                  //lat = (xn["lat"].Value);
                  //lon = (xn["lng"].Value);
                  lat = (xn.ChildNodes[0].InnerText);
                  lon = (xn.ChildNodes[1].InnerText);
                  break;
              }
          }
          catch { }

      }
       
    }
}
